package com.adinnet.admin.appVersion.service.impl;

import com.adinnet.admin.appVersion.model.AppVersion;
import com.adinnet.admin.appVersion.mapper.AppVersionMapper;
import com.adinnet.admin.appVersion.model.AppVersionReq;
import com.adinnet.admin.appVersion.service.AppVersionService;
import com.adinnet.admin.common.service.CommonService;
import com.adinnet.core.JsonResult;
import com.adinnet.core.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * app版本管理 服务实现类
 * </p>
 *
 * @author liukp
 * @since 2020-09-23
 */
@Service
public class AppVersionServiceImpl extends ServiceImpl<AppVersionMapper, AppVersion> implements AppVersionService {

    @Autowired
    private CommonService commonService;

    @Override
    public PageResult<AppVersion> list(AppVersionReq req) {
        Page<AppVersion> iPage = new Page<>(req.getPage(), req.getLimit());
        List<AppVersion> list = baseMapper.list(iPage,req);
        return new PageResult<AppVersion>(list, iPage.getTotal());
    }

    @Override
    public String add(AppVersion appVersion, HttpServletRequest request) {
        baseMapper.insert(appVersion);
        commonService.saveOperation(request,"APP版本管理-新增");
        return "操作成功";
    }

    @Override
    public JsonResult del(Integer id, HttpServletRequest request) {
        AppVersion appVersion=new AppVersion();
        appVersion.setId(id);
        appVersion.setDeleted(1);
        baseMapper.updateById(appVersion);
        commonService.saveOperation(request,"APP版本管理-删除");
        return JsonResult.ok("操作成功");
    }

    @Override
    public JsonResult update(Integer id, HttpServletRequest request) {
        baseMapper.updateAppVersion(id);
        commonService.saveOperation(request,"APP版本管理-启用");
        return JsonResult.ok("操作成功");
    }
}
